package com.qishanor.realty.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.Console;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qishanor.framework.util.R;
import com.qishanor.realty.model.RealtyIntro;
import com.qishanor.realty.model.dto.RealtyIntroDto;
import com.qishanor.realty.model.vo.RealtyIntroVo;
import com.qishanor.realty.service.RealtyIntroService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;


/**
 * 房产活动介绍关系控制器
 *
 * @author 周振林
 * @date 2023-02-21 09:40:25
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/realty/intro" )
public class RealtyIntroController {

    private final  RealtyIntroService realtyIntroService;

    /**
     * 分页查询
     */
    @GetMapping("/page" )
    @SaCheckPermission("realty_realtyintro_view" )
    public R getRealtyIntroPage(Page page, RealtyIntro realtyIntro) {
        return R.ok(realtyIntroService.page(page, Wrappers.query(realtyIntro)));
    }


    @GetMapping("/{id}" )
    @SaCheckPermission("realty_realtyintro_view" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(realtyIntroService.getById(id));
    }




    @PostMapping
//    @SaCheckPermission("realty_realtyintro_add" )
    @SaIgnore
    public R save(@RequestBody RealtyIntro realtyIntro) {
        return R.ok(realtyIntroService.save(realtyIntro));
    }


    @PutMapping
    @SaCheckPermission("realty_realtyintro_edit" )
    public R updateById(@RequestBody RealtyIntro realtyIntro) {
        return R.ok(realtyIntroService.updateById(realtyIntro));
    }


    @DeleteMapping("/{id}" )
    @SaCheckPermission("realty_realtyintro_del" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(realtyIntroService.removeById(id));
    }


}
